package com.dust.yuheadline.common.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 高翔宇
 * @since 2024/4/30 周二 上午9:15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    /**
     * 响应码
     */
    private int code;
    /**
     * 消息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;

    public Result<T> success(T data) {
        this.code = 200;
        this.message = "操作成功";
        this.data = data;
        return this;
    }

    public Result<T> success(T data, String message) {
        this.code = 200;
        this.message = message;
        this.data = data;
        return this;
    }

    public Result<T> success(String message) {
        this.code = 200;
        this.message = message;
        this.data = null;
        return this;
    }

    public Result<T> error(int code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
        return this;
    }

    public Result<T> error(ResponseCode responseCode) {
        this.code = responseCode.getCode();
        this.message = responseCode.getMessage();
        this.data = null;
        return this;
    }
}
